package com.xinxin.socket.handler;

import com.google.common.collect.Lists;
import com.xinxin.socket.decoder.NetMsgDecoder;
import com.xinxin.socket.encoder.NetMsgEncoder;
import io.netty.channel.ChannelHandler;

import java.util.List;

/**
 * @author ys
 * @date 2020/8/9
 */
public abstract class NetMsgHandlerHolder implements ChannelHandlerHolder {

    @Override
    public final ChannelHandler[] handlers() {
        List<ChannelHandler> handlers = Lists.newArrayList(
                com.xinxin.socket.handler.ChannelHandler.getInstance(),
                new NetMsgDecoder(),
                new NetMsgEncoder()
        );

        List<NetMsgHandler> handlers1 = Lists.newArrayList();
        addHandler(handlers1);
        handlers.addAll(handlers1);

        return handlers.toArray(new ChannelHandler[0]);
    }

    protected abstract void addHandler(List<NetMsgHandler> handlers);
}
